<?php

/**
 * Rewards controller.
 *
 * This file will render views from views/pages/
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class RewardsController extends AppController {

	/**
	 * Controller name
	 *
	 * @var string
	 */
	public $name = 'Rewards';

	/**
	 * This controller does not use a model
	 *
	 * @var array
	 */
	public $uses = array();

	public function admin_index() {
		if (!empty($this->data)) {
			switch ($this->data['Paginate']['task']) {
				case 'add':
					$this->Dashboard->redirect(array('action' => 'add'));
			}
		}
		$rewards = $this->Reward->getRewards();
		$this->set(compact('rewards'));
	}

	public function admin_add() {
		if (!empty($this->data)) {
			$this->Reward->create();
			if ($this->Reward->save($this->data)) {
				$this->setFlash(__('The reward has been saved'), 'success');
				$this->redirect(array('action' => 'add'));
			} else {
				$this->setFlash(__('The reward count not be saved'));
			}
		}
	}

	public function admin_edit($id = null) {
		$reward = $this->Reward->read(null, $id);
		$this->Dashboard->error(!$reward);
		if (!empty($this->data)) {
			if ($this->Reward->save($this->data)) {
				$this->setFlash(__('The reward has been saved'), 'success');
				$this->redirect(array('action' => 'index'));
			} else {
				$this->setFlash(__('The reward count not be saved'));
			}
		} else {
			$this->data = $reward;
		}
		$this->set('reward', $reward);
	}

	public function admin_delete($id = null) {
		if ($this->Reward->delete($id)) {
			$this->setFlash(__('The user has been deleted'), 'success');
		} else {
			$this->setFlash(__('The user count not be deleted'));
		}
		$this->Dashboard->redirect(array('action' => 'index'), true, true);
	}

}
